from django.db import models

# Create your models here.

#时间
class BaseModel(models.Manager):
    create_time = models.DateTimeField(auto_now_add=True)  #创建时间
    update_time = models.DateTimeField(auto_now=True) #更新时间



#地区信息表
class Areas(models.Manager):
    name = models.CharField(max_length=50,verbose_name='地区名称')
    postcode = models.IntegerField(default=0,verbose_name='地区邮编')
    class Meta:
        db_table = 'area'
        verboser_name = '地区表'

    def __str__(self):
        return self.name

#进出账表
class Bill(BaseModel):
    companyname = models.CharField(max_length=200,verbose_name = '公司名称')
    goodsname = models.CharField(max_length=200,verbose_name = '货品名称')
    goodsnum = models.IntegerField(default=0, verbose_name='供货数量')
    price = models.DecimalField(max_digits=7,decimal_places=2,verbose_name='供货金额')
    class Meta:
        db_table = 'bill'
        verbose_name = '进出账表'

#业务员信息表
class Salseman(models.Manager):
    salsnum = models.CharField(max_length=20,verbose_name='业务员编号')
    salsname = models.CharField(max_length=20,verbose_name='业务员名称')
    age = models.IntegerField(default=0)
    gender = models.CharField(max_length=20,verbose_name='性别')
    salslen = models.IntegerField(default=0,verbose_name='工龄')
    mobile = models.CharField(max_length=20,verbose_name='手机号')
    class Meta:
        db_table = 'salseman'
        verbose_name = '业务员信息'

#客户信息表
class Client(BaseModel):
    company = models.ForeignKey('Bill',to_field='companyname',on_delete=models.CASCADE)
    zhuyewu = models.CharField(max_length=20,verbose_name='主营业务')
    area = models.ForeignKey('Areas',to_field='name',on_delete=models.CASCADE)
    linkman = models.CharField(max_length=200,verbose_name='联系人')
    linkjob = models.CharField(max_length=200,verbose_name='联系业务')
    linkmobile = models.CharField(max_length=20,verbose_name='联系人电话')
    linkgender = models.CharField(max_length=20,verbose_name='联系人性别')
    postalcode = models.ForeignKey('Areas',to_field='postcode',on_delete=models.CASCADE)
    salsname = models.ForeignKey('Salseman',to_field='salsname',on_delete=models.CASCADE)
    client = models.BooleanField(default=False)

    class Meta:
        db_table = 'client'
        verbose_name = '客户信息表'




